package listener;

import lombok.extern.slf4j.Slf4j;
import tool.RobotTool;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

/**
 * @author zhangpeiwen
 * @since 2020/10/1
 */
@Slf4j
public class WindowDragListener extends MouseAdapter {
    private Point mouseDownCompCoords = null;

    @Override
    public void mouseMoved(MouseEvent e) {
        super.mouseMoved(e);
//        RobotTool.setMouseLocation(e.getPoint());
//        System.out.println(e.getPoint());
    }

    @Override
    public void mousePressed(MouseEvent e) {
        super.mousePressed(e);
        mouseDownCompCoords = e.getPoint();
    }

    @Override
    public void mouseReleased(MouseEvent e) {
        super.mouseReleased(e);
        mouseDownCompCoords = null;
    }

    @Override
    public void mouseDragged(MouseEvent e) {
        super.mouseDragged(e);Point currCoords = e.getLocationOnScreen();
        JFrame window = (JFrame)e.getSource();
        window.setLocation(currCoords.x - mouseDownCompCoords.x, currCoords.y - mouseDownCompCoords.y);
    }
}
